/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */



package Presentacion;


import Negocio.Configuracion;

import Negocio.SMTP;

import Negocio.Hilo;

/**
 *
 * @author Analia
 */
public class FramePrincipal extends javax.swing.JFrame
{

    /** Creates new form FramePrincipal */

    private Configuracion configuracion;
    private Hilo hilo;
    private SMTP email;


    public FramePrincipal()
    {
        initComponents();
        //this.configuracion = new Configuracion("virtual.fcet.uagrm.edu.bo","grupo3sa","grupo3grupo3",25,110,false);
        this.configuracion = new Configuracion("virtual.fcet.uagrm.edu.bo","grupo20sa","grupo20grupo20",25,110,false);
    }
   

    public Configuracion getConfiguracion()
    {
        return configuracion;
    }
    
    public void setConfiguracion(Configuracion configuracion)
    {
        this.configuracion = configuracion;
    }
    

     public Hilo getHilo()
     {
         return this.hilo;
     }

     public void setHilo(Hilo hilo)
     {
         this.hilo = hilo;
     }


     public void conectar()
     {
         System.out.println("Configurando Conexion....  \n");

         this.hilo = new Hilo(this.configuracion);
         System.out.println("Configurando Conexion.... 1  \n");
         this.hilo.start();
         System.out.println("Configurando Conexion.... 2 \n");
         this.email = new SMTP(this.configuracion);
         System.out.println("Configurando Conexion.... 3 \n");
         this.hilo.setActivo(true);
         System.out.println("Configurando Conexion.... 4 \n");
    }

    public void desconectar()
    {
         this.hilo.setActivo(false);
    }

    public void Enviar(String mail_from, String rcpt_to, String subject,String contenido)
    {
        email.conexionSMTP();
        email.enviar(mail_from,rcpt_to,subject,contenido);
    }

    public void quitEnviar()
    {
        email.quit();
    }




    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        BarraMenu = new javax.swing.JMenuBar();
        MenuServidor = new javax.swing.JMenu();
        MenuConectar = new javax.swing.JMenuItem();
        MenuDesconectar = new javax.swing.JMenuItem();
        MenuConfigurar = new javax.swing.JMenuItem();
        MenuCliente = new javax.swing.JMenu();
        MenuEnviarCorreo = new javax.swing.JMenuItem();
        MenuBandejaEntrada = new javax.swing.JMenuItem();
        MenuSalir = new javax.swing.JMenuItem();
        MenuMas = new javax.swing.JMenu();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setBackground(new java.awt.Color(9, 14, 4));

        BarraMenu.setBackground(new java.awt.Color(44, 176, 233));

        MenuServidor.setText("Servidor");

        MenuConectar.setText("Conectar");
        MenuConectar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                MenuConectarActionPerformed(evt);
            }
        });
        MenuServidor.add(MenuConectar);

        MenuDesconectar.setText("Desconectar");
        MenuDesconectar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                MenuDesconectarActionPerformed(evt);
            }
        });
        MenuServidor.add(MenuDesconectar);

        MenuConfigurar.setText("Configurar");
        MenuConfigurar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                MenuConfigurarActionPerformed(evt);
            }
        });
        MenuServidor.add(MenuConfigurar);

        BarraMenu.add(MenuServidor);

        MenuCliente.setText("Cliente");
        MenuCliente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                MenuClienteActionPerformed(evt);
            }
        });

        MenuEnviarCorreo.setText("Enviar Correo");
        MenuEnviarCorreo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                MenuEnviarCorreoActionPerformed(evt);
            }
        });
        MenuCliente.add(MenuEnviarCorreo);

        MenuBandejaEntrada.setText("Bandeja de Entrada");
        MenuBandejaEntrada.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                MenuBandejaEntradaActionPerformed(evt);
            }
        });
        MenuCliente.add(MenuBandejaEntrada);

        MenuSalir.setText("Salir");
        MenuSalir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                MenuSalirActionPerformed(evt);
            }
        });
        MenuCliente.add(MenuSalir);

        BarraMenu.add(MenuCliente);

        MenuMas.setText("Mas");
        BarraMenu.add(MenuMas);

        setJMenuBar(BarraMenu);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 409, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 277, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void MenuConectarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_MenuConectarActionPerformed

        conectar();
}//GEN-LAST:event_MenuConectarActionPerformed

    private void MenuDesconectarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_MenuDesconectarActionPerformed

        desconectar();
    }//GEN-LAST:event_MenuDesconectarActionPerformed

    private void MenuConfigurarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_MenuConfigurarActionPerformed

        FrameConfiguracion frmConfiguracion = new FrameConfiguracion(this);
        frmConfiguracion.setVisible(true);
        this.setVisible(false);

    }//GEN-LAST:event_MenuConfigurarActionPerformed

    private void MenuEnviarCorreoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_MenuEnviarCorreoActionPerformed

        FrameEnviarCorreo frmEnvio = new FrameEnviarCorreo(this);
        frmEnvio.setVisible(true);
        this.setVisible(false);
    }//GEN-LAST:event_MenuEnviarCorreoActionPerformed

    private void MenuBandejaEntradaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_MenuBandejaEntradaActionPerformed

        FrameBandejaEntrada revisarCorreo = new FrameBandejaEntrada(this);
        revisarCorreo.setVisible(true);
        this.setVisible(false);

    }//GEN-LAST:event_MenuBandejaEntradaActionPerformed

    private void MenuSalirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_MenuSalirActionPerformed

                   System.exit(1);

    }//GEN-LAST:event_MenuSalirActionPerformed

    private void MenuClienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_MenuClienteActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_MenuClienteActionPerformed

    



    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new FramePrincipal().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuBar BarraMenu;
    private javax.swing.JMenuItem MenuBandejaEntrada;
    private javax.swing.JMenu MenuCliente;
    private javax.swing.JMenuItem MenuConectar;
    private javax.swing.JMenuItem MenuConfigurar;
    private javax.swing.JMenuItem MenuDesconectar;
    private javax.swing.JMenuItem MenuEnviarCorreo;
    private javax.swing.JMenu MenuMas;
    private javax.swing.JMenuItem MenuSalir;
    private javax.swing.JMenu MenuServidor;
    // End of variables declaration//GEN-END:variables

}
